"""
Kafka配置文件
"""

# Kafka服务器配置
KAFKA_CONFIG = {
    'bootstrap.servers': 'localhost:9092',
    'client_id': 'air_quality_client',
    'group_id': 'air_quality_group',
    'auto_offset_reset': 'earliest',
    'enable_auto_commit': True,
    'auto_commit_interval_ms': 5000
}

# Kafka主题配置
TOPICS = {
    'raw_data': 'air_quality_raw',
    'processed_data': 'air_quality_processed',
    'predictions': 'air_quality_predictions'
}

def get_producer_config():
    """获取生产者配置"""
    return {
        'bootstrap_servers': KAFKA_CONFIG['bootstrap_servers'],
        'client_id': KAFKA_CONFIG['client_id']
    }

def get_kafka_config():
    """获取完整的Kafka配置"""
    return {
        'bootstrap_servers': KAFKA_CONFIG['bootstrap_servers'],
        'raw_data_topic': TOPICS['raw_data'],
        'prediction_topic': TOPICS['predictions'],
        'group_id': KAFKA_CONFIG['group_id'],
        'auto_offset_reset': KAFKA_CONFIG['auto_offset_reset'],
        'enable_auto_commit': KAFKA_CONFIG['enable_auto_commit'],
        'auto_commit_interval_ms': KAFKA_CONFIG['auto_commit_interval_ms']
    }

def get_consumer_config(group_id=None):
    """获取消费者配置"""
    config = {
        'bootstrap_servers': KAFKA_CONFIG['bootstrap_servers'],
        'auto_offset_reset': KAFKA_CONFIG['auto_offset_reset'],
        'enable_auto_commit': KAFKA_CONFIG['enable_auto_commit'],
        'auto_commit_interval_ms': KAFKA_CONFIG['auto_commit_interval_ms']
    }
    if group_id:
        config['group_id'] = group_id
    else:
        config['group_id'] = KAFKA_CONFIG['group_id']
    
    return config